package com.tailyou.hms.smartcity.ui.act;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.bumptech.glide.Glide;
import com.tailyou.hms.smartcity.R;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

public class SplashActivity extends AppCompatActivity {

    private List<Integer> imgRes = new ArrayList<>();
    private FrameLayout flSetting;
    private Banner banner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        imgRes.add(R.mipmap.bg_splash1);
        imgRes.add(R.mipmap.bg_splash2);
        imgRes.add(R.mipmap.bg_splash3);
        imgRes.add(R.mipmap.bg_splash4);
        imgRes.add(R.mipmap.bg_splash5);
        banner = findViewById(R.id.banner);
        flSetting = findViewById(R.id.flSetting);
        banner.addBannerLifecycleObserver(this);
        banner.setIndicator(new CircleIndicator(this));
        banner.setAdapter(new BannerImageAdapter(imgRes) {
            @Override
            public void onBindView(Object o, Object o2, int i, int i1) {
                BannerImageHolder imageHolder = (BannerImageHolder) o;
                Glide.with(SplashActivity.this).load(o2).into(imageHolder.imageView);
            }
        });
        banner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                flSetting.setVisibility(i==4? View.VISIBLE:View.GONE);
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

}